package gameobj;

import java.awt.Graphics;
import java.util.List;

import manager.ElementManager;
import render.MainUI;
import render.Model;
import render.SimpleModel;

public class Player extends Actor {
	private ElementManager em = null;
	private MainUI ui = null;
	public static boolean addattack=false;
	
	public Player() {
		super();
		this.setW(50);
		this.setH(65);
		this.setHealth(100);
		this.setMaxHealth(100);
		this.setAttackSpeed(15);
		em = ElementManager.get();
		ui = new MainUI(this);
	}

	@Override
	protected void attack() {
		Bullet bullet = new Bullet();
		bullet.setX(getX()+25);
		bullet.setY(getY());
		bullet.setH(50);
		bullet.setW(50);
		bullet.setSpeed(7);
		bullet.setPlayerOwned(true);
		bullet.setModel(bulletModel);
//		添加进管理
		em.add(ElementType.ITEM, bullet);
		if(addattack) {
			Bullet bullet1 = new Bullet();
			bullet1.setX(getX());
			bullet1.setY(getY());
			bullet1.setH(50);
			bullet1.setW(50);
			bullet1.setSpeed(8);
			bullet1.setPlayerOwned(true);
			bullet1.setModel(bulletModel);
//			添加进管理
			em.add(ElementType.ITEM, bullet1);
			Bullet bullet2 = new Bullet();
			bullet2.setX(getX()+50);
			bullet2.setY(getY());
			bullet2.setH(50);
			bullet2.setW(50);
			bullet2.setSpeed(8);
			bullet2.setPlayerOwned(true);
			bullet2.setModel(bulletModel);
//			添加进管理
			em.add(ElementType.ITEM, bullet2);
		}
	}
	
	@Override
	public void render(Graphics g) {
		super.render(g);
		ui.draw(g);
	}


	public void death() {
		this.setAlive(false);
	}

	@Override
	public void getHurt(int damage) {
		this.setHealth(getHealth()-damage);
		if(this.getHealth()<=0)
		{
			this.setHealth(0);
			System.out.println("\nplayer死亡！！！\n");
			this.death();
		}
	}

}
